home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 3 / Amiga Tools 3.iso / audio / deliay014 / dev / src / zxaystrc.s < prev   
Text File  |  1995-07-06  |  8KB  |  385 lines

  1. ;---------------T
  2.  
  3. DEBUG    equ    0
  4.  
  5.     incdir    Include40/
  6.     include    misc/AYPlayer.i
  7.     include    misc/mine.i
  8.     incdir    ''
  9.  
  10.     ifne    DEBUG
  11.  
  12.     lea    song(pc),a0
  13.     bsr    initsound
  14.     bsr    interrupt
  15.     rts
  16.  
  17. song    dc.b    0,1,2,3
  18.     dc.w    50814
  19.     dc.w    0
  20.     dc.b    0;,0
  21.     incbin    zx:archive/megamixcomp.001
  22.     endc
  23.  
  24. * STRC (SoundTracker Raxoft Compiler) AY Player for
  25. * SoundTracker songs compiled by my compiler/compressor
  26.  
  27. * 1 Initial version
  28.  
  29.     STRUCTURE    STRC_Song,0
  30.     UBYTE    ams_assignA    ;0-3 specifies, what amiga channel will be
  31.     UBYTE    ams_assignB    ;assigned to each ay channel (A-C, noise)
  32.     UBYTE    ams_assignC
  33.     UBYTE    ams_assignN
  34.     UWORD    strc_getabs    ;start of data in ZX ram
  35.     WORD    ams_fadeoffset    ;precise fade specification
  36.     UWORD    ams_fadelen    ;how long to fade (not supported by DT so far)
  37.                 ;set to zero for neverending song
  38.     ;and so on...
  39.  
  40. ; The Player itself.
  41.  
  42. dd
  43.     AYPLAYERHEADER    STRC
  44.     dc.b    12+1        ;custom ayfreq transpose
  45.     ifeq    DEBUG
  46. AYbase    ds.l    1        ;where ay registers should be "outed"
  47.     else
  48. AYbase    dc.l    ay        ;where ay registers should be "outed"
  49.     endc
  50.     ifeq    DEBUG
  51. AYass    ds.l    1        ;where ay channel assignment should be copied
  52.     else
  53.     dc.l    ay
  54.     endc
  55. AYfreq    ds.l    1        ;from where we take AY frequencies
  56.     dc.w    0        ;initplayer
  57.     dc.w    0        ;endplayer
  58.     dc.w    initsound-*
  59.     dc.w    0        ;endsound
  60.     dc.w    interrupt-*
  61.     dc.w    nextpatt-*
  62.     dc.w    prevpatt-*
  63.     dc.b    'SoundTracker (Raxoft) 1.2',0
  64.     dc.b    '(C) 1990 Patrik Rak - Raxoft',0
  65.     dc.b    '(C) 1994 Patrik Rak - Raxoft',0
  66.     even
  67.  
  68. initsound    moveq    #0,d1            ;clear variables
  69.     lea    vars,a1
  70.     moveq    #(data-vars)/2-1,d0
  71. .fill    move.w    d1,(a1)+
  72.     dbra    d0,.fill
  73.  
  74.     move.l    AYass(pc),a2        ;feed PlayAY
  75.     move.l    (a0)+,(a2)        ;with channel assignement
  76.  
  77.     move.w    (a0)+,d1        ;get getabs (upper word is zero)!!
  78.  
  79.     move.w    (a0)+,d2        ;gate fadeoffset
  80.  
  81.     move.w    (a0)+,songfade-data(a1)    ;store fadelen
  82.  
  83.     moveq    #0,d0
  84.     move.b    (a0),d0            ;delay
  85.     move.w    (a0),d3
  86.     and.w    #$ff,d3
  87.     mulu    d0,d3            ;pattlen in VBIs...
  88.  
  89.     moveq    #envtab,d0
  90.     add.l    a0,d0
  91.     move.l    d0,(a1)+    ;data
  92.     sub.l    d1,a0
  93.     move.l    a0,(a1)+    ;getabsset
  94.     move.w    #$0101,(a1)+    ;curdelay & curpattlen
  95.     moveq    #posbeg-envtab,d1
  96.     add.l    d1,d0
  97.     move.l    d0,(a1)+        ;position
  98.  
  99.     move.w    d3,(a1)+    ;vbipattlen
  100.     move.w    d2,(a1)+    ;fadeofset
  101.  
  102.     move.l    d0,a0
  103. .count    add.w    d3,d2
  104.     addq.l    #7,a0
  105.     tst.b    1(a0)
  106.     bne.b    .count
  107.     move.w    d2,(a1)        ;songlen
  108.     rts
  109.  
  110. nextpatt    lea    position,a1
  111.     move.l    (a1),a0
  112.     tst.b    1(a0)
  113.     bne.b    patterns        ;no next pattern
  114.     rts
  115.  
  116. prevpatt    lea    position,a1
  117.     move.l    (a1),a0
  118.     subq.l    #7,a0
  119.     subq.l    #7,a0
  120.     moveq    #posbeg-xy,d0
  121.     add.l    data-position(a1),d0
  122.     cmp.l    d0,a0
  123.     bcc.b    patterns
  124.     move.l    d0,a0
  125. patterns    move.w    #$101,-2(a1)
  126.     move.l    a0,(a1)+
  127.     move.w    (a1)+,d3
  128.     move.w    (a1)+,d2
  129.     tst.w    (a1)
  130.     bne.b    initsound\.count
  131.     rts
  132.  
  133. interrupt    lea    ay,a6    ;base
  134.     lea    data-ay(a6),a0
  135.     move.l    (a0)+,a5    ;data
  136.     move.l    (a0)+,d7    ;getabsset
  137.     moveq    #0,d6        ;use d6 as obsl1 in original
  138.     subq.b    #1,(a0)
  139.     bne.b    .samenote
  140.     moveq    #-1,d6        ;signal new tones
  141.     move.b    delay-xy(a5),(a0)+
  142.     subq.b    #1,(a0)
  143.     bne.b    .samenote
  144.     move.b    pattlen-xy(a5),(a0)+
  145.     move.l    (a0),a0
  146.     tst.b    1(a0)
  147.     bne.b    .notend
  148.     lea    posbeg-xy(a5),a0
  149. .notend    bsr.b    getabs
  150.     move.l    d0,ch1-ay(a6)
  151.     bsr.b    getabs
  152.     move.l    d0,ch2-ay(a6)
  153.     bsr.b    getabs
  154.     move.l    d0,ch3-ay(a6)
  155.     move.b    (a0)+,transpose+1-ay(a6)
  156.     move.l    a0,position-ay(a6)
  157. .samenote    lea    ch1-ay(a6),a2
  158.     move.l    a6,a3            ;lea    freqa-ay(a6),a3
  159.     lea    vola-ay(a6),a4
  160.     moveq    #0,d5
  161.     st    strobe-ay(a6)    ;all off
  162. .loop    bsr.b    obsluha
  163.     lea    chlen(a2),a2
  164.     addq.l    #2,a3
  165.     addq.l    #1,a4
  166.     addq.b    #1,d5
  167.     cmp.b    #3,d5
  168.     bne.b    .loop
  169.     move.l    AYbase(pc),a1
  170.     moveq    #11-1,d0
  171. .outy    move.b    (a6)+,(a1)+
  172.     dbra    d0,.outy
  173.     move.b    (a6)+,d0
  174.     beq.b    .done
  175.     move.b    (a6)+,(a1)+
  176.     move.b    (a6),(a1)+
  177.     move.b    d0,(a1)
  178. .done    lea    songlen-volc-1(a4),a0
  179.     moveq    #0,d0
  180.     tst.w    (a0)
  181.     beq.b    .exit
  182.     subq.w    #1,(a0)+
  183.     bne.b    .exit
  184.     move.w    (a0),d0
  185. .exit    rts
  186.  
  187.  
  188. getabs    moveq    #0,d0        
  189.     move.b    (a0)+,d1
  190.     move.b    (a0)+,d0
  191.     lsl.w    #8,d0
  192.     move.b    d1,d0
  193.     add.l    d7,d0
  194.     rts
  195.  
  196. gettab    move.l    d2,d0    ;because tables are even
  197. gettab2    move.w    (a0,d0.w),d0
  198.     ror    #8,d0
  199.     add.l    d7,d0
  200.     move.l    d0,a0
  201.     add    d3,a0
  202.     rts
  203.  
  204. ;a2 channel, a3 freq, a4 volume, d5 how much rotate strobe
  205.  
  206. obsluha    tst    d6        ;new tones?
  207.     beq.b    .same
  208.     bsr.w    newtone
  209.     bra.b    .cont
  210. .same    bsr.w    sametone
  211. .cont    moveq    #0,d2
  212.     move.b    smp(a2),d2    ;sample number
  213.     add.w    d2,d2
  214.     lea    tonetab-xy(a5,d2),a0
  215.     bsr.b    getabs
  216.     move.l    d0,a0
  217.     moveq    #0,d3
  218.     move.b    pos(a2),d3
  219.     add    d3,a0
  220.     add    d3,a0
  221.     move.b    (a0)+,d1
  222.     move.b    (a0),d4
  223.     lsl.w    #8,d4
  224.     move.b    d1,d4
  225.  
  226.     add.w    d4,d4    ;can be negative...
  227.     add.w    d4,d4
  228.     add.w    d4,d4
  229.  
  230.     moveq    #0,d0
  231.     move.b    orn(a2),d0
  232.     add.w    d0,d0
  233.     lea    orntab-xy(a5),a0
  234.     bsr.b    gettab2
  235.     move.w    transpose-ay(a6),d0
  236.     add.b    (a0),d0
  237.     add.b    tone(a2),d0
  238.     add.w    d0,d0
  239.     move.l    AYfreq(pc),a0
  240.     add.w    d0,a0
  241.     add.w    (a0),d4
  242.     move.w    d4,(a3)        ;freq
  243.  
  244.     move.l    a5,a0        ;lea envtab-xy(a5),a0
  245.     bsr.b    gettab
  246.     move.b    (a0),d4
  247.     beq.b    .envel0
  248.     lea    noistab-xy(a5),a0
  249.     bsr.b    gettab
  250.     move.b    (a0),d3
  251.     move.b    d3,d2
  252.     moveq    #-2,d0        ;strobe for tone on
  253.     add.b    d2,d2        ;noise off?
  254.     bcs.b    .nonoise
  255.     moveq    #-10,d0        ;strobe for tone and noise on
  256.     and.b    #31,d3
  257.     move.b    d3,noise-ay(a6)    ;noise
  258. .nonoise    add.b    d2,d2
  259.     bcc.b    .toneon
  260.     addq.b    #1,d0        ;turn the tone off
  261. .toneon    rol.b    d5,d0
  262.     and.b    d0,strobe-ay(a6)
  263.     and.b    #16,(a4)    ;keep just previous env on flag!!!
  264.     or.b    d4,(a4)        ;vol
  265. .envel0    rts
  266.  
  267. newtone    move.l    (a2),a0
  268.     moveq    #0,d0
  269.     move.b    (a0)+,d0
  270.     bmi.b    silentqm
  271.     move.b    d0,tone(a2)
  272.     move.b    (a0)+,d0
  273.     move.b    (a0)+,d2
  274.     move.l    a0,(a2)
  275.     
  276.     moveq    #15,d1
  277.     and.b    d0,d1
  278.     lea    smpmem(a2),a0
  279.     lsr.b    #4,d0
  280.     bne.b    .newsmpl
  281.     move.b    (a0),d0
  282. .newsmpl    move.b    d0,(a0)+
  283.     move.b    d0,(a0)+
  284.     clr.b    (a0)+
  285.     move.b    #32,(a0)+
  286.     add    d0,d0
  287.     lea    smpltab-xy(a5,d0.w),a1
  288.     move.w    (a1),(a0)        ;even table
  289.  
  290.     moveq    #%01111101,d0
  291.     btst    d1,d0
  292.     bne.b    .exit
  293.     clr.b    orn(a2)
  294.     clr.b    (a4)
  295.     cmp.b    #1,d1
  296.     beq.b    .exit
  297.     cmp.b    #15,d1
  298.     bne.b    .env
  299.     and    d1,d2
  300.     move.b    d2,orn(a2)
  301.     rts
  302. .env    move.b    #16,(a4)
  303.     move.b    d1,envtype-ay(a6)
  304.     move.b    d2,envfreq-ay(a6)    ;fill only lower byte
  305. .exit    rts
  306.  
  307. silentqm    move.l    a0,(a2)
  308.     addq.b    #1,d0
  309.     bne.b    sametone
  310.     clr.b    smpmem(a2)
  311. silent    clr.b    smp(a2)
  312.     clr.b    (a4)
  313.     ;rts    ;to behave exactly as origal I omit this logical rts
  314.  
  315. sametone    addq.b    #1,pos(a2)
  316.     and.b    #31,pos(a2)
  317.     subq.b    #1,len(a2)
  318.     bne.b    .exit
  319.     move.b    rpos(a2),d0
  320.     beq.b    silent
  321.     subq.b    #1,d0
  322.     move.b    d0,pos(a2)
  323.     move.b    rlen(a2),len(a2)
  324. .exit    rts
  325.  
  326.     section    variables,bss
  327. vars
  328. ay
  329. freqa    ds.w    1
  330. freqb    ds.w    1
  331. freqc    ds.w    1
  332. noise    ds.b    1
  333. strobe    ds.b    1
  334. vola    ds.b    1
  335. volb    ds.b    1
  336. volc    ds.b    1
  337. envtype    ds.b    1        ;note that these two
  338. envfreq    ds.w    1        ;lines are swapped!!!
  339.  
  340.     rsreset
  341. strm    rs.l    1        ;Position in pattern stream
  342. tone    rs.b    1        ;Current tone
  343. orn    rs.b    1        ;Ornament number (tone slides)
  344. smpmem    rs.b    1        ;sample nr (same as smp, but this remains intact)
  345. smp    rs.b    1        ;Current sample nr (freq slides, env & noise)
  346. pos    rs.b    1        ;Position in sample/ornament
  347. len    rs.b    1        ;Sample/orn length remaining to loop test
  348. rpos    rs.b    1        ;If, then where start repeating sample/orn
  349. rlen    rs.b    1        ;What len use when looping
  350. ;following three are maintained directly in this conversion
  351. ;ctrl    rs.b    1        ;Partial tone noise strobe
  352. ;freq    rs.w    1        ;Freq calculated for this channel
  353. ;vol    rs.b    1        ;Volume for this channel
  354. chlen    rs.b    0
  355.  
  356. ch1    ds.b    chlen
  357. ch2    ds.b    chlen
  358. ch3    ds.b    chlen
  359.  
  360. data    ds.l    1        ;song data
  361. getabsset    ds.l    1        ;ZX Ram base
  362.  
  363. curdelay    ds.b    1
  364. curpattlen    ds.b    1
  365. position    ds.l    1
  366. vbipattlen    ds.w    1
  367. fadeoffset    ds.w    1
  368. songlen    ds.w    1
  369. songfade    ds.w    1
  370. transpose    ds.w    1
  371. varsend
  372. varslen    equ    *-vars
  373.  
  374.     rsreset
  375. delay    rs.b    1    ;how long each note sounds (VBIs)
  376. pattlen    rs.b    1    ;how many notes in each pattern
  377. tonetab    rs.w    16    ;ptrs to seq of freq slides
  378. orntab    rs.w    16    ;ptrs to seq of tone slides
  379. xy    rs.b    0
  380. envtab    rs.w    16    ;ptrs to seq of volume values
  381. noistab    rs.w    16    ;ptrs to seq of noise values + tone&noise mask
  382. smpltab    rs.w    16    ;table of rpos and rlen s
  383. posbeg    rs.b    0
  384.  
  385.